{% extends  'm/base.html' %}
{% block title %}{{ item.article_title|safe }}{% endblock %}
{% block custom_css_js %}
<style>
  body{ text-align:center}
  .title {
    font-size: 1.2rem;
    font-weight: bold;
    color: #555;
    line-height: 25px;
    margin-bottom: 6px;
    text-align: left;
  }
  .summary {
    line-height: 25px;
    color: #777;
    padding-right: 0;
    text-align: left;
  }
  .price {
    padding: 15px 10px 8px;
    overflow: hidden;
    margin: 0;
  }
  .price em {
    float: left;
    text-align: left;
    color: #e6312a;
    width: 64%;
    height: 25px;
    line-height: 25px;
    font-size: 1.0rem;
    overflow: hidden;
    font-weight: bold;
  }
  .buy-btn {
    width: 90px;
    height: 25px;
    float: right;
    line-height: 25px;
    font-size: 1.2rem;
    margin-bottom: 5px;
    margin-right: 5px;
    color: #fff;
    border-radius: 12px;
    -webkit-border-radius: 12px;
    background-color: #f04848;
    text-align: center;
  }
  a {
    text-decoration: none;
  }
  .div { margin:0 auto; }
</style>
{% endblock %}
{% block base_content %}
{% if request.user.is_authenticated %}
<div id="dialogs">
    <div class="js_dialog" id="iosDialog2" style="display: none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__bd">
              <p id="img_p"><img src="/static/img/loading3.gif" alt="loading" /></p>
              <p id="desc_p">请稍等...正在生成二维码分享海报</p>
            </div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary">关闭</a>
            </div>
        </div>
    </div>
</div>
{% endif %}
<div class="page article js_show">
    <div class="page__bd">
        <article class="weui-article">
            <span class="title">{{ item.article_title|safe }}</span>
            <section>
                <section>
                    <div class="div">
                      <img {% if item.article_pic_style %} {{item.article_pic_style|safe}} {% else %} width="200px" height="200px" style="margin-top:0px" {% endif %} src="{% if item.qiniu_pic %}{{ item.qiniu_pic }}{% else %}//img.ztm.me/img/noimg.png{% endif %}" alt="{{ item.article_title|safe }}" />
                    </div>
                    <div class="price">
                      <em>{{ item.article_price }}</em>
                      {% if item.commodity_url_refer or item.commodity_url %}
                      <a class="buy-btn" href="{% if item.commodity_url_refer %}{{ item.commodity_url_refer }}{% else %}{{item.commodity_url}}{% endif %}" target="_blank">{{ item.article_mall.name }}</a>
                      {% endif %}
                    </div>
                    <div class="summary">
                      {% if item.article_content %}
                      {{ item.article_content|safe }}
                      {% else %}
                      {{ item.article_summary|safe }}
                      {% endif %}
                    </div>
                </section>
                <section>
                  {% if request.user.is_staff and request.user.is_superuser %}
                  <div class="div">
                    <a href="javascript:;" class="weui-btn weui-btn_warn" id="showIOSDialog2">生成海报分享给好友</a>
                  </div>
                  <br />
                  <div class="div">
                      <a href="javascript:;" class="weui-btn weui-btn_primary" id="showIOSDialog3">生成固定二维码海报</a>
                  </div>
                  {% else %}
                    {% if item.active %}
                      <div class="div">
                        <a href="javascript:;" class="weui-btn weui-btn_warn" id="showIOSDialog2">生成海报分享给好友</a>
                      </div>
                    {% endif %}
                  {% endif %}
                  <!--
                  <div style="margin:0 auto;text-align:center;margin-top:20px;">
                    <h3>关注『每周精选购(ztmlink)』获取更多资讯</h3>
                    <img src="https://img.ztm.me/wechat/qrcode_for_gh_6cm.jpg" alt="每周精选购二维码" />
                  </div>
                  -->
                  {% comment "disable@20180629" %}
                  {% if request.user.is_staff and request.user.is_superuser %}
                  <div class="div">
                    <a href="/account/broadcast/{{item.id}}/" class="weui-btn weui-btn_primary">广播发送该商品</a>
                  </div>
                  {% endif %}
                  {% endcomment %}
                </section>
            </section>
        </article>
    </div>
    <div class="page__ft j_bottom">
        <a href="javascript:home()"></a>
    </div>
</div>
<script type="text/javascript">
  $(function(){
      var $iosDialog2 = $('#iosDialog2');
      // 生成临时二维码
      $('#showIOSDialog2').on('click', function(){
          $iosDialog2.fadeIn(200);
          setTimeout(function() {
            document.getElementById("img_p").innerHTML = '<img src="https://www.ztm.me/weixin/share/post/?item_id={{ item.pk }}&qrcode_type=0" alt="post" style="width:242px;height:362px;" />';
            document.getElementById("desc_p").innerText = '长按海报并选择“发送给朋友”！';
          }, 1000);
      });
      // 生成固定二维码
      $('#showIOSDialog3').on('click', function(){
        $iosDialog2.fadeIn(200);
        setTimeout(function() {
          document.getElementById("img_p").innerHTML = '<img src="https://www.ztm.me/weixin/share/post/?item_id={{ item.pk }}&qrcode_type=1" alt="post" style="width:242px;height:362px;" />';
          document.getElementById("desc_p").innerText = '长按海报并选择“发送给朋友”！';
        }, 1000);
    });

      $('#dialogs').on('click', '.weui-dialog__btn', function(){
        $(this).parents('.js_dialog').fadeOut(200);
      });
  });
</script>
{% if jssdk_signature %}
<script>
// https://segmentfault.com/q/1010000002566983/a-1020000002567095
// var targetUrl = location.href.split('#')[0];
// targetUrl = targetUrl.replace('&', '%26');
wx.ready(function(){
    // 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
    wx.onMenuShareTimeline({
        title: '{{ item.article_title|safe }}', // 分享标题
        desc: "{{ item.article_summary|safe }}", // 分享描述
        link: 'https://www.ztm.me/youhui/detail/{{ item.id }}/?referrer={{ referrer }}',
        imgUrl: "https:{% if item.qiniu_pic %}{{ item.qiniu_pic }}{% else %}//img.ztm.me/img/noimg.png{% endif %}?imageMogr/v2/thumbnail/300x300" // 分享图标
    });
    // 获取“分享给朋友”按钮点击状态及自定义分享内容接口
    wx.onMenuShareAppMessage({
        title: '{{ item.article_title|safe }}', // 分享标题
        desc: "{{ item.article_summary|safe }}", // 分享描述
        link: 'https://www.ztm.me/youhui/detail/{{ item.id }}/?referrer={{ referrer }}',
        imgUrl: "https:{% if item.qiniu_pic %}{{ item.qiniu_pic }}{% else %}//img.ztm.me/img/noimg.png{% endif %}?imageMogr/v2/thumbnail/300x300", // 分享图标
        type: 'link' // 分享类型,music、video或link，不填默认为link
    });
    wx.error(function(res){
      alert(res.errMsg);
    });
});
</script>
{% endif %}
{% endblock %}